<?php

namespace app\admin\model;

use think\Model;

class Bookclass extends Model
{
    // 表名
    protected $name = 'bookclass';

    protected $id;
    protected $level;
    protected $bookclass_id;
    protected $weigh;
    protected $status;
    protected $createtime;
    protected $updatetime;

    //获取一级分类
    public function getList(){
        $this->arr = $this->where(['status'=>1,'bookclass_id'=>0])->order('weigh desc')->select();
        return $this->getChild();
    }

    //获取所有分类
    public function getAllList(){
        $List = $this->where(['status'=>1,'bookclass_id'=>0])->order('weigh desc')->select();
        foreach ($List as $key=>$value){
            $List[$key]['child'] = $this->getChild($value['id']);
        }
        return $List;
    }

    //获取所有分类
    public function getAllList2($id){
        $List = $this->where(['status'=>1,'bookclass_id'=>0,'id'=>$id])->order('weigh desc')->select();
        foreach ($List as $key=>$value){
            $List[$key]['child'] = $this->getChild($value['id']);
        }
        return $List;
    }

    //获取二级分类
    public function getTwoList($id){
        $List = $this->where(['status'=>1,'bookclass_id'=>$id])->order('weigh desc')->select();
        return $List;
    }

    //获取三级分类
    public function getThreeList($where){
        $List = $this->where($where)->order('weigh desc')->select();
        return $List;
    }


    /**
     * 得到子级数组
     * @param int
     * @return array
     */
    public function getChild($myid)
    {
        $twoList = $this->where(['status'=>1,'bookclass_id'=>$myid])->order('weigh desc')->select();
        foreach ($twoList as $key=>$value) {
            $twoList[$key]['threeList'] = $this->where(['status'=>1,'bookclass_id'=>$value['id']])->order('weigh desc')->select();
        }
        return $twoList;
    }


}
